#ifndef MAININTERFACE_H
#define MAININTERFACE_H

#include <QWidget>
#include <QDateTime>
#include <QTimer>
#include <QSerialPort>
#include <QtSerialBus>
#include <QModbusDataUnit>
#include <QModbusClient>
#include <QProcess>
#include <windows.h>
#include <QMessageBox>

namespace Ui {
class mainInterface;
}

class mainInterface : public QWidget
{
    Q_OBJECT

public:
    explicit mainInterface(QWidget *parent = nullptr);
    ~mainInterface();

typedef union /*申明一个联合体*/
{
float dataf;
uint32_t data32;
uint16_t data16[2];
uint8_t data8[4];
} data_t;

private slots:
    void on_exitPushButton_clicked();

    void readFlowData();

    void updateDateTime();

    void handleReadResult();

    void on_keyboardPushButton_clicked();


    void on_historyPushButton_clicked();

    void on_setPushButton_clicked();

    void on_helpPushButton_clicked();

private:
    Ui::mainInterface *ui;

    QTimer *dataTimer;
    QTimer *clockTimer;

    QModbusClient *modbusDevice;

    void setupModbusConnection();
    float parseFloatFromRegisters(const QVector<quint16> &registers);
    quint16 swapBytes(quint16 value);

    QProcess *keyboardProcess;
    bool keyboardVisible;

    float convertToFloat(quint16 reg1, quint16 reg2, bool isBigEndian);



};

#endif // MAININTERFACE_H
